package com.SpringWebSocket.task;

import com.SpringWebSocket.config.WebSocketUsers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;

@Slf4j
@Component
@EnableScheduling
public class task {

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");

    @Scheduled(fixedDelay = 500)
    public void test1() {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                WebSocketUsers.sendMessageToUsersByText(simpleDateFormat.format(System.currentTimeMillis()));
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                WebSocketUsers.sendMessageToUsersByText(simpleDateFormat.format(System.currentTimeMillis()));
            }
        });
        t1.start();
        t2.start();
    }

    //    @Scheduled(fixedDelay = 500)
    public void test2() {
        WebSocketUsers.sendMessageToUsersByText("456");
    }

    //    @Scheduled(fixedDelay = 500)
    public void test3() {
        WebSocketUsers.sendMessageToUsersByText("789");
    }
}
